﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Trade.Library.Common
{
    /// <summary>
    /// 生成静态页面类
    /// </summary>
    public class HtmlPage
    {
        /// <summary>
        /// 新建静态页面
        /// </summary>
        /// <param name="text">内容</param>
        /// <param name="path">路径</param>
        /// <returns>返回生成的文件名</returns>
        public static string CreatePage(string text, string path)
        {
            string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + Common.Function.GetRandomStr(4) + ".html";
            string allpath = path + "/" + filename;
            FileStream myFs = new FileStream(allpath, FileMode.Create);
            StreamWriter mySw = new StreamWriter(myFs,Encoding.UTF8);
            mySw.Write(text);
            mySw.Close();
            myFs.Close();
            return filename;
        }
        /// <summary>
        /// 修改静态页面
        /// </summary>
        /// <param name="text"></param>
        /// <param name="path"></param>
        /// <returns></returns>
        public static int EditPage(string text, string path)
        {
            int resout;
            try
            {
                FileStream myFs = new FileStream(path, FileMode.Create);
                StreamWriter mySw = new StreamWriter(myFs, Encoding.Default);
                mySw.Write(text);
                mySw.Close();
                myFs.Close();
                resout = 1;
            }
            catch (Exception)
            {
                resout = 0;
            }
            return resout;
        }
    }
}
